#include <stdlib.h>
#include "Sound.h"
#include <fmod.hpp>


HANDLE SndInit()
{
	using namespace FMOD;
	System *pSndSys = NULL;
	void *extradriverdata = 0;
	System_Create(&pSndSys);
	pSndSys->init(32, FMOD_INIT_NORMAL, extradriverdata);
	return pSndSys;
}

void SndRelease( HANDLE hSys)
{
	using namespace FMOD;
	System* snd = (System*)hSys;
	if(snd)
		snd->release();
}

void SndUpdate( HANDLE hSys )
{
	using namespace FMOD;
	System* snd = (System*)hSys;
	if(snd)
		snd->update();
}

HANDLE SndLoad( HANDLE hSys, const char* sndfile )
{
	using namespace FMOD;
	System* snd = (System*)hSys;
	Sound *pSnd = NULL;
	if( FMOD_OK== snd->createSound(sndfile, FMOD_DEFAULT, 0, &pSnd) )
		return pSnd;

	return NULL;
}

HANDLE SndPlay( HANDLE hSys, HANDLE hSnd)
{
	using namespace FMOD;
	System* sys = (System*)hSys;
	Sound* snd = (Sound*) hSnd;

	Channel    *channel = NULL;
	if(sys && snd)
		sys->playSound(snd, 0, false, &channel);

	return channel;
}
